﻿using NEasy.Ldap.Attributes;

namespace NEasy.Ldap.Entity
{
    /// <summary>
    /// base class for all AD data transfer objects
    /// which provides the basic infrastructure
    /// for all AD entities.
    /// </summary>
    [LdapObject()]
    public abstract class LdapObjectBase
    {
        #region repository connection

        /// <summary>
        /// internal reference to the repository (for additional queries)
        /// </summary>
        protected ILdapRepository Repository { get; private set; }

        /// <summary>
        /// set the repository. required to attach the repository to an entity
        /// </summary>
        /// <param name="repository"></param>
        internal void SetRepository(ILdapRepository repository)
        {
            this.Repository = repository;
        }

        #endregion

        #region schema class definition
       
        /// <summary>
        /// name of the schema class for object creation
        /// </summary>
        protected string schemaClassName = "top";

        /// <summary>
        /// name of the schema class
        /// </summary>
        /// <remarks>required during object creation</remarks>
        public string SchemaClassName
        {
            get { return schemaClassName; }
        }

        #endregion

        #region base ldap readonly properties

        /// <summary>
        /// distunguished name of the object type
        /// </summary>
        [LdapReadOnlyAttribute("distinguishedName")]
        public string DistinguishedName { get; set; }

        /// <summary>
        /// object class to identify the object type
        /// </summary>
        [LdapReadOnlyAttribute("objectClass")]
        public string ObjectClass { get; set; }

        /// <summary>
        /// canonical name as unique id of the object
        /// </summary>
        [LdapReadOnlyAttribute("CN")]
        public string CanonicalName { get; set; }

        #endregion

        #region ToString

        /// <summary>
        /// returns the <see cref="DistinguishedName"/> of the entity
        /// </summary>
        public override string ToString()
        {
            return this.DistinguishedName;
        }

        #endregion
    }
}
